package com.bw.visitor.adapter

import android.graphics.Color
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bw.visitor.R
import com.bw.visitor.entity.VisitorEntity
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class VisitorAdapter : BaseQuickAdapter<VisitorEntity , BaseViewHolder>(R.layout.visitor_item) {
    override fun convert(holder: BaseViewHolder, item: VisitorEntity) {
        holder.setText(R.id.v_time, "${item.appointmentTime}")
        holder.setText(R.id.v_shen, item.visitStatus)
        if (item.visitStatus == "已通过") {
            val textView = holder.getView<TextView>(R.id.v_shen)
            textView.setTextColor(Color.parseColor("#4D947D"))
            textView.setBackgroundResource(R.drawable.v_tonguo)
        } else if (item.visitStatus == "待审核") {
            val textView = holder.getView<TextView>(R.id.v_shen)
            textView.setTextColor(Color.parseColor("#9B4F1E"))
            textView.setBackgroundResource(R.drawable.v_shenhe)
        } else if (item.visitStatus == "已完成") {
            val textView = holder.getView<TextView>(R.id.v_shen)
            textView.setTextColor(Color.parseColor("#5A6270"))
            textView.setBackgroundResource(R.drawable.v_wanc)
        } else if (item.visitStatus == "驳回") {
            val textView = holder.getView<TextView>(R.id.v_shen)
            textView.setTextColor(Color.parseColor("#ffffff"))
            textView.setBackgroundResource(R.drawable.v_bohui)
        }
        holder.setText(R.id.v_name, item.visitorName)
        holder.setText(R.id.v_Phone, item.phoneNumber)
        holder.setText(R.id.v_Lai, item.purpose)
        holder.setText(R.id.v_Fang, item.employeeId.toString())

        if (item.requestParking) {
            val imageView = holder.getView<ImageView>(R.id.v_car)
            Glide.with(imageView.context).load(com.bw.common.R.drawable.car_lan).into(imageView)

            val textView = holder.getView<TextView>(R.id.v_car_shen)
            textView.setTextColor(Color.parseColor("#1E87E4"))
            textView.setText("已申请访客车辆: ")

            val textView1 = holder.getView<TextView>(R.id.v_shenCar)
            textView1.text = "A区-12号"
            textView1.setTextColor(Color.parseColor("#1E87E4"))
        } else {
            val imageView = holder.getView<ImageView>(R.id.v_car)
            Glide.with(imageView.context).load(com.bw.common.R.drawable.car_hui).into(imageView)

            val textView = holder.getView<TextView>(R.id.v_car_shen)
            textView.setTextColor(Color.parseColor("#CDCDCD"))
            textView.setText("未申请访客车位")

            val textView1 = holder.getView<TextView>(R.id.v_shenCar)
            textView1.setTextColor(Color.parseColor("#CDCDCD"))
            textView1.text = ""
        }
    }
}